package service

import (
	"errors"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
	"outsourced-projects/pkg/utils"
)

type Wx struct {
	Base
}

func (wx Wx) AuthGetUserDetail(c *gin.Context) {
	var err error
	//数据获取
	jsondata := make(map[string]interface{})
	err = c.BindJSON(&jsondata)
	if err != nil {
		ReturnJson(c, 500, err.Error(), gin.H{})
		return
	}
	if jsondata["code"] == "" {
		ReturnJson(c, 400, errors.New("code 不能为空").Error(), gin.H{})
		return
	}
	ticket, err := utils.CgiBinAuthGetuserinfo(cast.ToString(jsondata["code"]))
	if err != nil {
		ReturnJson(c, 500, err.Error(), gin.H{})
		return
	}

	datas, err := utils.CgiBinAuthGetuserdetail([]byte(fmt.Sprintf(`{"user_ticket": "%s"}`, ticket)))
	if err != nil {
		ReturnJson(c, 500, err.Error(), gin.H{})
		return
	}
	fmt.Println(datas)
	ReturnJson(c, 200, "操作成功", gin.H{})
}
